<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');

class My_layout
{

    var $obj;
    var $layout;

    function My_layout($layout = "")
    {
        $this->obj =& get_instance();
        $this->layout = $layout;
    }

    function setLayout($layout)
    {
      $this->layout = $layout;
    }

    function view($view, $data=null, $return=false)
    {
        
        $loadedData = array();
        $loadedData['content_for_layout'] = $this->obj->load->view($view,$data,true);

        if($return) {
            $output = $this->obj->load->view($this->layout, $loadedData, true);
            return $output;
        }
        else {
            $this->obj->load->view($this->layout, $loadedData, false);
        }
    }


    public function format_price($price) {
        $length = strlen($price);
        $newValue = '';
        while ($length > 0) {
            $temp =  substr($price, $length - 3, 3);
            if($length < 3) {
                $temp =  substr($price, 0, $length);
            }
            //echo($length -3);
            if(strlen($newValue)>0){
                $newValue = $temp.'.'.$newValue;
            } else {
                $newValue = $temp;
            }
            $length = $length -3;
        }
        return $newValue;
    }
    
}